package com.hc.wego.controller;

import com.hc.wego.bean.PageBean;
import com.hc.wego.converter.UserConverter;
import com.hc.wego.domain.entity.User;
import com.hc.wego.domain.query.UserQuery;
import com.hc.wego.domain.vo.UserVO;
import com.hc.wego.service.UserService;
import com.hc.wego.utils.ReflectUtil;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 *
 * @author hc
 * @date 2025-06-20 8:55
 */
@Controller
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;
    @Resource
    private UserConverter userConverter;

    @GetMapping("/openPage")
    public ModelAndView openPage(UserQuery query, ModelAndView mav) {
        mav.setViewName("/list");
        query.setColumns(ReflectUtil.getTableFileName(UserVO.class));
        final PageBean<User> userPageBean = userService.getPage(query);
        final PageBean<UserVO> userVOPageBean = userConverter.userPageBean2userVOPageBean(userPageBean);
        mav.addObject("pageBean", userVOPageBean);

        return mav;
    }

}